package com.zb.controller;


import com.zb.entity.dto.StoreAuthorDto;
import com.zb.entity.dto.StoreAuthorSelect;
import com.zb.result.Result;
import com.zb.service.ZjAdmStoreAuthorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 后台仓库权限表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-07-14
 */
@Api(tags = "仓库权限类接口")
@RestController
@RequestMapping("/storeAuthor")
public class ZjAdmStoreAuthorController {
    @Autowired
    private ZjAdmStoreAuthorService admStoreAuthorService;

    @ApiOperation("新增或修改权限类型")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid StoreAuthorDto authorDto) {
        admStoreAuthorService.save(authorDto);
        return Result.success(null == authorDto.getId()? "新增权限类型成功" : "更改权限类型成功");
    }

    @ApiOperation("仓库权限列表查询")
    @PostMapping("/getList")
    public Result getList(@RequestBody StoreAuthorSelect authorSelect) {
        return Result.success("获取仓库权限列表成功！").data(admStoreAuthorService.getList(authorSelect));
    }

    @ApiOperation("批量禁用或启用仓库权限")
    @PostMapping("/disble")
    public Result disable(@RequestParam @ApiParam("是否禁用：false-否，true-是") boolean disable,
                         @RequestBody @ApiParam("仓库权限ID集合") List<Long> idList) {
        admStoreAuthorService.updateBatchDisableById(idList, disable);
        return Result.success(disable? "禁用仓库权限成功" : "启用仓库权限成功");
    }

}
